def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def find_largest_prime(num):
    if len(str(num)) != 4:
        return 0
    
    digits = [int(d) for d in str(num)]
    digits.sort(reverse=True)
    
    for i in range(4, 0, -1):
        for j in range(i):
            if is_prime(int("".join(map(str, digits[j:i])))):
                return int("".join(map(str, digits[j:i]))
    
    return 0

num = int(input())
result = find_largest_prime(num)
print(result)
